package handle

import (
	"database/sql"
	_ "github.com/go-sql-driver/mysql"
	"log"
	"time"
)

var Conn *sql.DB

var Conf map[string]*string

func Connect() {
	//
	var err error
	var url string
	if conf != nil {
		url = *conf["url"]
	} else {
		url = "root:allScore123!@tcp(cdb-ef5yokqy.bj.tencentcdb.com:10120)/stormragetech?allowNativePasswords=true&parseTime=true"
	}
	Conn, err = sql.Open("mysql", url)
	if err != nil {
		panic("connect to mysql failed, " + err.Error())
	}
	Conn.SetMaxIdleConns(10)
	Conn.SetMaxOpenConns(30)
	Conn.SetConnMaxLifetime(time.Second * 60)
	log.Printf("[INFO] database connect successfully, %v", Conn)
}
